# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

include(FetchContent)

if("avh" IN_LIST IOTSDK_FETCH_LIST)
    FetchContent_MakeAvailable(avh)
endif()

if(avh_POPULATED)

    add_library(avh-sockets
        ${avh_SOURCE_DIR}/interface/vsocket/iot_socket.c
    )

    target_include_directories(avh-sockets
        PRIVATE
            ${avh_SOURCE_DIR}/interface/include
    )

    target_link_libraries(avh-sockets
        PRIVATE
            cmsis-sockets-api
            cmsis-rtos-api
    )

    # iot_socket.c has a dependency on arm_vsocket but expects this header to be included alongside
    # other headers with the CMSIS_device_header preprocessor macro. We don't have acces to the
    # value of CMSIS_device_header. This is why we feed the header through the commandline.
    target_compile_options(avh-sockets PRIVATE -include "arm_vsocket.h")

endif()
